package com.zzyl.nursing.job;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zzyl.nursing.domain.Contract;
import com.zzyl.nursing.service.IContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component("UpdateContractStatusJob")
public class UpdateContractStatusJob {
    @Autowired
private IContractService contractService;
    public void  updateStatus(){
        //未生效--已生效
       // update contract set status = 1where status=0 and now()between start_date and end_date
      //  update contract set status =1 where status=0 start_date < now()and end_date
        LambdaUpdateWrapper<Contract> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(Contract::getStatus,1);
        updateWrapper.eq(Contract::getStatus,0);
        updateWrapper.lt(Contract::getStartDate, LocalDateTime.now());
        updateWrapper.gt(Contract::getEndDate,LocalDateTime.now());
        contractService.update(updateWrapper);
//已生效----已过期

        LambdaUpdateWrapper<Contract> updateWrapper1 = new LambdaUpdateWrapper<>();
        updateWrapper1.set(Contract::getStatus,2);
        updateWrapper1.eq(Contract::getStatus,1);
        updateWrapper1.lt(Contract::getEndDate, LocalDateTime.now());

        contractService.update(updateWrapper1);



        System.out.println("执行了自己的定时任务");
    }
}
